
#pragma once

namespace reload
{
	class ReloadPacket;
	class ReloadOverlay;
	class AttachReqAns;

	class ReloadNetworkDataContext : public asyframe::UdpHandlerContext
	{
	public:
		ReloadNetworkDataContext();
		ReloadNetworkDataContext(boost::shared_ptr<ReloadNetworkDataContext> _pReloadNetworkDataContext);
		virtual ~ReloadNetworkDataContext();

		boost::shared_ptr<ReloadPacket> pReloadPacket_;
		boost::shared_ptr<asyframe::WildcardElement> pWildcardElement_;
	};

	class IReloadNetworkDataAction : public virtual asyframe::ITcpAction
	{
	public:
		IReloadNetworkDataAction();
		virtual ~IReloadNetworkDataAction();

		virtual retT onRead( boost::shared_ptr<asyframe::DataHandlerContext> _pDataHandlerContext, std::size_t _bytesTransferred, const boost::system::error_code& e, std::size_t _timeoutCount);
		virtual retT onWrite(boost::shared_ptr<asyframe::DataHandlerContext> _pDataHandlerContext, std::size_t _bytesTransferred, const boost::system::error_code& e, std::size_t _timeoutCount);
		virtual retT onConnect(boost::shared_ptr<asyframe::DataHandlerContext> _pDataHandlerContext, const boost::system::error_code& e, std::size_t _timeoutCount);
	};

	class ReloadNetworkDataHandler : public asyframe::DataHandler
	{
	public:
		ReloadNetworkDataHandler();
		virtual ~ReloadNetworkDataHandler();

		virtual retT asyncRead(boost::shared_ptr<asyframe::IoBuffer> _pBuffers, boost::shared_ptr<asyframe::DataHandlerContext> _pDataHandlerContext = boost::shared_ptr<asyframe::DataHandlerContext>(), asyframe::DataCallBackFunType _dataCallBackFun = NULL);
		virtual retT asyncWrite(boost::shared_ptr<asyframe::IoBuffer> _pBuffers, boost::shared_ptr<asyframe::DataHandlerContext> _pDataHandlerContext = boost::shared_ptr<asyframe::DataHandlerContext>(), asyframe::DataCallBackFunType _dataCallBackFun = NULL);
		virtual retT asyncConnect(const void* _pEndpoint, boost::shared_ptr<asyframe::DataHandlerContext> _pDataHandlerContext = boost::shared_ptr<asyframe::DataHandlerContext>(), asyframe::BaseCallBackFunType _dataCallBackFun = NULL);
		virtual retT asyncConnect(const std::string& _address, unsigned short _port, boost::shared_ptr<asyframe::DataHandlerContext> _pDataHandlerContext = boost::shared_ptr<asyframe::DataHandlerContext>(), asyframe::BaseCallBackFunType _dataCallBackFun = NULL);

		virtual retT init();

		virtual boost::shared_ptr<boost::asio::ip::tcp::socket> getTcpSocket();

		retT prepareIceCandidates(boost::shared_ptr<ReloadOverlay> _pReloadOverlay, boost::shared_ptr<AttachReqAns> _pAttachReqAns);

	protected:
		boost::shared_ptr<asyframe::TcpHandler> pTcpHandler_;
	};
} /*namespace reload*/
